#include <Ape/EventModel/Callback.h>

namespace Ape {
	namespace EventModel {
		Callback::Callback (Object* object)
				: m_Object (object),
				m_Active (false),
				m_Neutralized (false),
				m_Orphaned (true)
		{
			object->__AppendCallback (this);
		}
		
		Callback::~Callback() {}
		
		void Callback::condDelete() {
			Callback* me = this;
			if (isNeutralized() && isOrphaned() )
				delete me;
		}
		
		void Callback::Activate() {
			m_Active = true;
		}
		void Callback::Deactivate() {
			m_Active = false;
		}
		bool Callback::isActive() const {
			return m_Active;
		}
		
		void Callback::Neutralize() {
			m_Neutralized = true;
			condDelete();
		}
		bool Callback::isNeutralized() const {
			return m_Neutralized;
		}
		
		void Callback::TakeCare() {
			m_Orphaned = false;
		}
		void Callback::Leave() {
			m_Orphaned = true;
			condDelete();
		}
		bool Callback::isOrphaned() const {
			return m_Orphaned;
		}
	}
}
